angular.module('mamApp').controller('anchorTagsModalController', ['$scope', 'AlbumManager', '$uibModalInstance', 'TagsManager', 'param','BaseValidations',
    function ($scope, AlbumManager, $uibModalInstance, TagsManager, param,BaseValidations) {
        $scope.dimensionsName = param.dimensionsName;
        var anchorId = "";
        $scope.formData = {status: 2, dimensionId: param.dimensionId};
        $scope.BaseValidations=BaseValidations;
        if (param.tag) {
            anchorId = param.tag.anchorId;
            $scope.formData.status = param.tag.status;
            $scope.formData.anchortagName = param.tag.anchortagName;

        }
        $scope.BaseValidations=BaseValidations;

        $scope.modelOk = function () {

            if (anchorId) {
                $scope.formData.anchortagName= $scope.formData.anchortagName.replace(/，|；|;|、|\s/g,",");
                TagsManager.anchorTagsEdit(anchorId, $scope.formData).then(function (result) {
                    if (result.data.c == "s") {
                        $uibModalInstance.close("ok");

                    } else {
                        $scope.nameCheck = true;
                        $scope.message=result.data.i;
                        //$uibModalInstance.close("error");

                    }
                })
            } else {
                $scope.formData.anchortagName= $scope.formData.anchortagName.replace(/，|；|;|、|\s/g,",");
                TagsManager.anchorTagsAdd($scope.formData).then(function (result) {
                    if (result.data.c == "s") {
                        $uibModalInstance.close("ok");

                    } else {
                        $scope.nameCheck = true;
                        $scope.message=result.data.i;
                        //$uibModalInstance.close("error");

                    }
                })
            }

        };

        $scope.modelCancel = function () {
            $uibModalInstance.close("cancel");
        };


    }])

